package org.qf.Test;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.qf.Dao.StudentDao;
import org.qf.entity.Student;

import java.io.IOException;
import java.io.InputStream;

public class Updatetest {
    public static void main(String[] args) {
//1.加载mybatis核心配置文件
        try {
            InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
//2.获取会话工厂
            SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
            SqlSessionFactory factory=builder.build(inputStream);
//3.获取会话
            SqlSession session = factory.openSession();
//4. 获取dao接口
            StudentDao studentDao = session.getMapper(StudentDao.class);
            Student student=new Student();
            student.setSid(1);
            student.setStuName("啥GG");
            student.setStuGender("男");
            int i = studentDao.updateStu(student);
//增加、删除、修改需要事务提交
            session.commit();
            if(i>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
